package com.wisedu.w5autocode.template;

import com.wisedu.w5autocode.views.*;
import com.wisedu.w5autocode.*;

public class QueryControllerTemplate
{
  protected static String nl;
  public static synchronized QueryControllerTemplate create(String lineSeparator)
  {
    nl = lineSeparator;
    QueryControllerTemplate result = new QueryControllerTemplate();
    nl = null;
    return result;
  }

  public final String NL = nl == null ? (System.getProperties().getProperty("line.separator")) : nl;
  protected final String TEXT_1 = "package ";
  protected final String TEXT_2 = ";" + NL + "" + NL + "import java.util.*;" + NL + "import ";
  protected final String TEXT_3 = ";" + NL + "import com.wiscom.epstar.web.EntityQueryController;" + NL + "import com.wiscom.epstar.core.service.EntityQueryContext;" + NL + "import javax.portlet.RenderRequest;" + NL + "import com.wiscom.epstar.core.model.BaseEntity;" + NL + "" + NL + "public class ";
  protected final String TEXT_4 = " extends EntityQueryController {" + NL + "\t" + NL + "\t@Override" + NL + "    protected void populateQueryContext(RenderRequest request, EntityQueryContext queryContext) throws Exception {" + NL + "    \tsuper.populateQueryContext(request,queryContext);" + NL + "    }" + NL + "    " + NL + "    @Override" + NL + "    protected List<? extends BaseEntity> loadEntities(RenderRequest request) throws Exception {" + NL + "    \tList<";
  protected final String TEXT_5 = "> list = (List<";
  protected final String TEXT_6 = ">)super.loadEntities(request);" + NL + "    \treturn list;" + NL + "    }" + NL + "" + NL + "}";

  public String generate(Object argument)
  {
    final StringBuffer stringBuffer = new StringBuffer();
    
	QueryControllerArgs qca = (QueryControllerArgs)argument;
	MyEntityModel mem = qca.getMyEntityModel();

    stringBuffer.append(TEXT_1);
    stringBuffer.append(qca.getControllerPackage() );
    stringBuffer.append(TEXT_2);
    stringBuffer.append(mem.getEntityPackageName() );
    stringBuffer.append(TEXT_3);
    stringBuffer.append(qca.getControllerName());
    stringBuffer.append(TEXT_4);
    stringBuffer.append(mem.getEntityClassName());
    stringBuffer.append(TEXT_5);
    stringBuffer.append(mem.getEntityClassName());
    stringBuffer.append(TEXT_6);
    return stringBuffer.toString();
  }
}
